package com.afkt.project.ui.slice;

import com.afkt.project.util.HomeUtils;
import com.afkt.project.util.LogUtils;

import com.ohos.afkt.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.window.dialog.ToastDialog;

public class CrashLogSlice extends AbilitySlice {

    private Button goBack;


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_crash_log);

        /**
         *设置返回
         * */
        goBack = (Button) findComponentById(ResourceTable.Id_btn_crash_back);
        if (goBack != null) {
            goBack.setClickedListener(component -> {
                onBackPressed();
            });
        }

        /**
         *
         * 捕获崩溃日志
         * */
        Button buttom = (Button) findComponentById(ResourceTable.Id_carsh_log);
        buttom.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                new ToastDialog(getContext()).setText("崩溃日志信息已输出到HiLog上").show();
                try{
                    Intent intent = HomeUtils.backDesktop();
                    startAbility(intent);
                }catch (Exception e){
                    LogUtils.info("CrashLog","崩溃日志："+e.toString());
                }
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
